package com.cms.recursoshumanos.ui;


import com.cms.recursoshumanos.cache.ListaContactosCache;
import com.cms.recursoshumanos.cache.UserInfoCache;
import com.cms.recursoshumanos.component.base.CustomButtonColored;
import com.cms.recursoshumanos.component.base.TwoColumnField;
import com.cms.recursoshumanos.constant.Constant;
import com.cms.recursoshumanos.container.ForegroundManager;
import com.cms.recursoshumanos.container.TwoColumnFieldManager;
import com.cms.recursoshumanos.engine.ScreenEngine;
import com.cms.recursoshumanos.handler.BeneficiosAdministrativosScreenHandler;
import com.cms.recursoshumanos.handler.MyUserDetailScreenHandler;
import com.cms.recursoshumanos.handler.ListaOcioScreenHandler;
import com.cms.recursoshumanos.handler.ListaReservacionScreenHandler;
import com.cms.recursoshumanos.handler.ListaTipoArticuloScreenHandler;
import com.cms.recursoshumanos.handler.ListaTipoEventosScreenHandler;
import com.cms.recursoshumanos.handler.ListaTipoMenuScreenHandler;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.XYEdges;
import net.rim.device.api.ui.component.ButtonField;
//import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.BorderFactory;

/**
 * A class extending the MainScreen class, which provides default standard
 * behavior for BlackBerry GUI applications.
 */
public final class MenuScreen extends RecursosHumanosScreen
{
    /**
     * Creates a new MyScreen object
     */
	//static Utileria tools = new Utileria();
	private CustomButtonColored boton_info_user,
								boton_comedor,
								boton_articulo,
								boton_carrito_compra,
								boton_vacaciones,
								boton_beneficios,
								boton_eventos,
								boton_ocio,
								boton_directorio,
								boton_lista_reservacion;
	
	public static MenuScreen instance = null;
	
	public static MenuScreen getInstance()
	{
		if (instance == null)
		{
			return new MenuScreen();
		}
		else
		{
			return instance;
		}
	}
	public MenuScreen() 
	{
		super(NO_VERTICAL_SCROLL | USE_ALL_HEIGHT );
		
		setComponents();
		
	}
	
	public void setComponents() 
	{
		setTitle("Menu Principal");
		
		ForegroundManager foreground = new ForegroundManager();
		
		TwoColumnFieldManager twoColumnManager = new TwoColumnFieldManager( Display.getWidth() / 2, USE_ALL_WIDTH );
        twoColumnManager.setBorder( BorderFactory.createBitmapBorder( new XYEdges( 10, 10, 10, 10 ), Bitmap.getBitmapResource( "border_simple_white.png" ) ) );
        twoColumnManager.setMargin( 10, 10, 10, 10 );
        twoColumnManager.setPadding( 6, 6, 6, 6 );

        //vfm = new VerticalFieldManager(Field.FIELD_HCENTER); 
        
        boton_info_user = new CustomButtonColored("INFO USER",ButtonField.CONSUME_CLICK | FIELD_HCENTER, Constant.COLOR_BUTTON_FOCUS); 

        boton_info_user.setChangeListener(new FieldChangeListener() 
        {
	   		public void fieldChanged(Field field, int context) 
	       	{ 
	   			MyUserDetailScreenHandler handler = new MyUserDetailScreenHandler();
	   			handler.getAllUserInfo(UserInfoCache.getInstance().getUsuario().getNombre_Usuario(),
	   								UserInfoCache.getInstance().getUsuario().getPassword());
	       	} 
		}); 
        
        boton_comedor = new CustomButtonColored("COMEDOR",ButtonField.CONSUME_CLICK | FIELD_HCENTER, Constant.COLOR_BUTTON_FOCUS); 

        boton_comedor.setChangeListener(new FieldChangeListener() 
        {
	   		public void fieldChanged(Field field, int context) 
	       	{ 
	   			ListaTipoMenuScreenHandler handler = new ListaTipoMenuScreenHandler();
	   			handler.getListadoTipoMenu(UserInfoCache.getInstance().getUsuario().getNombre_Usuario(), 
	   					UserInfoCache.getInstance().getUsuario().getPassword());
	   			
	       	} 
		}); 
        
        boton_articulo = new CustomButtonColored("ARTICULO",ButtonField.CONSUME_CLICK | FIELD_HCENTER, Constant.COLOR_BUTTON_FOCUS); 

        boton_articulo.setChangeListener(new FieldChangeListener() 
        {
	   		public void fieldChanged(Field field, int context) 
	       	{ 
	   			
	   			ListaTipoArticuloScreenHandler handler = new ListaTipoArticuloScreenHandler();
	   			handler.getListadoTipoArticulo(UserInfoCache.getInstance().getUsuario().getNombre_Usuario(), 
	   					UserInfoCache.getInstance().getUsuario().getPassword());
	       	} 
		});
        
        boton_carrito_compra = new CustomButtonColored("CARRITO DE COMPRA",ButtonField.CONSUME_CLICK | FIELD_HCENTER, Constant.COLOR_BUTTON_FOCUS); 

        boton_carrito_compra.setChangeListener(new FieldChangeListener() 
        {
	   		public void fieldChanged(Field field, int context) 
	       	{ 
	   			ScreenEngine.getInstance().goCarritoCompra();
	       	} 
		});
        boton_vacaciones = new CustomButtonColored("VACACIONES",ButtonField.CONSUME_CLICK | FIELD_HCENTER, Constant.COLOR_BUTTON_FOCUS); 

        boton_vacaciones.setChangeListener(new FieldChangeListener() 
        {
	   		public void fieldChanged(Field field, int context) 
	       	{ 
	   			ScreenEngine.getInstance().goVacacionesMainScreen();
   			} 
		});
        boton_beneficios = new CustomButtonColored("BENEFICIOS",ButtonField.CONSUME_CLICK | FIELD_HCENTER, Constant.COLOR_BUTTON_FOCUS); 

        boton_beneficios.setChangeListener(new FieldChangeListener() 
        {
	   		public void fieldChanged(Field field, int context) 
	       	{ 
	   			BeneficiosAdministrativosScreenHandler handler = new BeneficiosAdministrativosScreenHandler();
	   			handler.getBeneficiosAdministrativos(UserInfoCache.getInstance().getUsuario().getNombre_Usuario(),
	   					UserInfoCache.getInstance().getUsuario().getPassword());
   			} 
		});
        boton_eventos = new CustomButtonColored("EVENTOS",ButtonField.CONSUME_CLICK | FIELD_HCENTER, Constant.COLOR_BUTTON_FOCUS); 

        boton_eventos.setChangeListener(new FieldChangeListener() 
        {
	   		public void fieldChanged(Field field, int context) 
	       	{ 
	   			ListaTipoEventosScreenHandler handler = new ListaTipoEventosScreenHandler();
	   			handler.getListaTipoEvento(UserInfoCache.getInstance().getUsuario().getNombre_Usuario(), 
	   					UserInfoCache.getInstance().getUsuario().getPassword());
	   			
   			} 
		});
        boton_ocio = new CustomButtonColored("ESTABLECIMENTO OCIO",ButtonField.CONSUME_CLICK | FIELD_HCENTER, Constant.COLOR_BUTTON_FOCUS); 

        boton_ocio.setChangeListener(new FieldChangeListener() 
        {
	   		public void fieldChanged(Field field, int context) 
	       	{ 
	   			ListaOcioScreenHandler handler = new ListaOcioScreenHandler();
	   			handler.getListadoOcio(UserInfoCache.getInstance().getUsuario().getNombre_Usuario(), 
	   					UserInfoCache.getInstance().getUsuario().getPassword());
	       	} 
		});
        
        boton_directorio = new CustomButtonColored("DIRECTORIO",ButtonField.CONSUME_CLICK | FIELD_HCENTER, Constant.COLOR_BUTTON_FOCUS); 

        boton_directorio.setChangeListener(new FieldChangeListener() 
        {
	   		public void fieldChanged(Field field, int context) 
	       	{ 
	   			ScreenEngine.getInstance().goListaContacto(ListaContactosCache.getInstance().getListaContacto());
	       	} 
		});
        
        boton_lista_reservacion = new CustomButtonColored("LISTA RESERVACION",ButtonField.CONSUME_CLICK | FIELD_HCENTER, Constant.COLOR_BUTTON_FOCUS); 

        boton_lista_reservacion.setChangeListener(new FieldChangeListener() 
        {
	   		public void fieldChanged(Field field, int context) 
	       	{ 
	   			ListaReservacionScreenHandler handler = new ListaReservacionScreenHandler();
	   			/*cambio*/handler.getListadoReservaciones(UserInfoCache.getInstance().getUsuario().getNombre_Usuario(), 
	   											UserInfoCache.getInstance().getUsuario().getPassword(),
	   											null);
	       	} 
		});
        Field both;
        both = new TwoColumnField( boton_info_user, boton_comedor, USE_ALL_WIDTH );
        both.setMargin( 6, 0, 6, 0 );
        twoColumnManager.add( both );
        
        both = new TwoColumnField( boton_articulo, boton_carrito_compra, USE_ALL_WIDTH );
        both.setMargin( 6, 0, 6, 0 );
        twoColumnManager.add( both );
        
        both = new TwoColumnField( boton_beneficios, boton_vacaciones, USE_ALL_WIDTH );
        both.setMargin( 6, 0, 6, 0 );
        twoColumnManager.add( both );
        
        both = new TwoColumnField( boton_eventos, boton_ocio , USE_ALL_WIDTH );
        both.setMargin( 6, 0, 6, 0 );
        twoColumnManager.add( both );
        
        both = new TwoColumnField( boton_directorio, boton_lista_reservacion , USE_ALL_WIDTH );
        both.setMargin( 6, 0, 6, 0 );
        twoColumnManager.add( both );
        
        foreground.add( twoColumnManager );
        add( foreground );
			
	}
	
	
}
